using ns0;
using ns4;
using System;
using System.Text;
namespace ns9
{
	public sealed class UPCEReader : UPCEANReader
	{
		private static readonly int[] int_8 = new int[]
		{
			1,
			1,
			1,
			1,
			1,
			1
		};
		private static readonly int[][] int_9 = new int[][]
		{
			new int[]
			{
				56,
				52,
				50,
				49,
				44,
				38,
				35,
				42,
				41,
				37
			},
			new int[]
			{
				7,
				11,
				13,
				14,
				19,
				25,
				28,
				21,
				22,
				26
			}
		};
		private int[] int_10;
		internal override BarcodeFormat BarcodeFormat
		{
			get
			{
				return BarcodeFormat.UPC_E;
			}
		}
		public UPCEReader()
		{
			this.int_10 = new int[4];
		}
		protected internal override int decodeMiddle(BitArray bitArray_0, int[] startRange, StringBuilder result)
		{
			int[] array = this.int_10;
			array[0] = 0;
			array[1] = 0;
			array[2] = 0;
			array[3] = 0;
			int size = bitArray_0.Size;
			int num = startRange[1];
			int num2 = 0;
			int num3 = 0;
			while (num3 < 6 && num < size)
			{
				int num4 = UPCEANReader.smethod_5(bitArray_0, array, num, UPCEANReader.int_7);
				result.Append((char)(48 + num4 % 10));
				for (int i = 0; i < array.Length; i++)
				{
					num += array[i];
				}
				if (num4 >= 10)
				{
					num2 |= 1 << 5 - num3;
				}
				num3++;
			}
			UPCEReader.smethod_6(result, num2);
			return num;
		}
		protected internal override int[] decodeEnd(BitArray bitArray_0, int endStart)
		{
			return UPCEANReader.smethod_4(bitArray_0, endStart, true, UPCEReader.int_8);
		}
		protected internal override bool checkChecksum(string string_0)
		{
			return base.checkChecksum(UPCEReader.convertUPCEtoUPCA(string_0));
		}
		private static void smethod_6(StringBuilder stringBuilder_1, int int_11)
		{
			for (int i = 0; i <= 1; i++)
			{
				for (int j = 0; j < 10; j++)
				{
					if (int_11 == UPCEReader.int_9[i][j])
					{
						stringBuilder_1.Insert(0, i.ToString());
						stringBuilder_1.Append(j.ToString());
					}
				}
			}
			throw ReaderException.Instance;
		}
		public static string convertUPCEtoUPCA(string upce)
		{
			char[] array = new char[6];
			SupportClass.GetCharsFromString(upce, 1, 7, array, 0);
			StringBuilder stringBuilder = new StringBuilder(12);
			stringBuilder.Append(upce.get_Chars(0));
			char c = array[5];
			switch (c)
			{
			case '0':
			case '1':
			case '2':
				stringBuilder.Append(array, 0, 2);
				stringBuilder.Append(c);
				stringBuilder.Append("0000");
				stringBuilder.Append(array, 2, 3);
				break;
			case '3':
				stringBuilder.Append(array, 0, 3);
				stringBuilder.Append("00000");
				stringBuilder.Append(array, 3, 2);
				break;
			case '4':
				stringBuilder.Append(array, 0, 4);
				stringBuilder.Append("00000");
				stringBuilder.Append(array[4]);
				break;
			default:
				stringBuilder.Append(array, 0, 5);
				stringBuilder.Append("0000");
				stringBuilder.Append(c);
				break;
			}
			stringBuilder.Append(upce.get_Chars(7));
			return stringBuilder.ToString();
		}
	}
}
